<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <a href="adduser.php">添加</a>
        <br/>
        <table border="1px">
            <tr>
                <th>编号</th>
                <th>用户名</th>
                <th>密码</th>
                <th>年龄</th>
                <th>性别</th>
                <th></th>
            </tr>
         <?php
        //mysqli_connect 获取一个数据库的连接对象,返回值是连接对象或者false
        //$hostname 表示连接的数据库的ip或者域名
        //$username 连接数据库使用的用户
        //$password 连接的用户的密码
        // $database 需要连接的数据库
        $hostname="127.0.0.1";
        $username="root";
        $password="abc123";
        $database="mybb_test";
        $connect=mysqli_connect($hostname, $username, $password, $database);
        if($connect){
//            echo "数据库连接成功！";
            //mysqli_set_charset 设置连接使用的字符集
            mysqli_set_charset($connect, "utf-8");
            $sqlstring="INSERT INTO `user_infos`( `username`, `upwd`, `age`, `sex`)"
                    . " VALUES ('张三','123456',18,'女')";
            //mysqli_query 执行sql语句并获得执行结果
            $sqlstring="select * from user_infos";
            $result=mysqli_query($connect, $sqlstring);
            //mysqli_fetch_array 获取结果集中某一行的记录
            $row=mysqli_fetch_array($result);
            while($row){
//            echo "<br/>\$row :".gettype($row);
//            foreach($row as $k=>$v){
//                echo "<br/>".$k."  ->  ".$v;
//            }
//            echo "<br/> uid:".$row["uid"]." username:".$row["username"]."upwd:".$row["upwd"]
//                    ." age:".$row["upwd"]." sex:".$row["sex"];
//            echo "<br/> uid:".$row[0]." username:".$row[1]."upwd:".$row[2]
//                    ." age:".$row[3]." sex:".$row[4];
                ?>
                <tr>
                    <td><?php echo $row["uid"]; ?></td>
                    <td><?php echo $row["username"]; ?></td>
                    <td><?php echo $row["upwd"]; ?></td>
                    <td><?php echo $row["sex"]; ?></td>
                    <td><?php echo $row["age"]; ?></td>
                    <td>
                        <a href="edituser.php?id=<?php echo $row["uid"]; ?>">编辑</a>
                        <a href="deluser.php?id=<?php echo $row["uid"]; ?>">删除</a>
                    </td>
                </tr>

            <?php
            $row=mysqli_fetch_array($result);
            }
            
        }else{
            echo "数据库连接失败";
        }
        //mysqli_close 释放数据库连接
        mysqli_close($connect);
        ?>
         </table>
    </body>
</html>
